﻿define(['admin/app', 'service/admin/quotaRecordService'], function (app) {
    "use strict";
    app.controller('quotaRecordController', function ($scope, $state, $stateParams, $location, $uibModal, utils, w5cValidator, quotaRecordService, baseService) {
        $scope.list = {};
        $scope.query = { page: 1, size: 20, name: '' };
        $.extend($scope.query, $stateParams);
        var methods = {
            search: function () {
                quotaRecordService.gets($scope.query).success(function (response) { $scope.model = response.data; });
            },
            search_page: function (page) {
                $scope.query.page = page;
                $location.search('page', $scope.query.page);
            },
            open_audit_action: function (model) {
                $uibModal.open({
                    templateUrl: 'audit_action.html',
                    controller: 'audit_action_Ctrl',
                    resolve: {
                        model: function () {
                            return model;
                        }
                    }
                }).result.then(function (model) {
                    methods.search();
                });
            },
            goBack: function () {
                history.back();
            }
           
        };
        angular.extend($scope, methods);
        if ($state.includes('app.advertisement.detail')) {
            methods.edit();
        } else {
            methods.search();
        }
    });
    app.controller('audit_action_Ctrl', function ($scope, $uibModalInstance, utils, quotaRecordService, model) {
        $scope.model = model;
        $scope.save = function () {
            quotaRecordService.audit({
                id: $scope.model.id, equota_record_audit: $scope.model.equota_record_audit_, audit_num: $scope.model.audit_num_, remark: $scope.model.remark_
            }).success(function (response) {
                utils.notify(response.result_msg, response.result_code == 1000 ? "success" : "warning");
                $uibModalInstance.close($scope.model);
            });
        };

        $scope.cancel = function () {
            $uibModalInstance.dismiss('cancel');
        };
    });
});